<?
$smarty=new Smarty();
if(!ANTIHACK) die("ANTIHACK...");
include_once("../includes/language_vi.php");
$smarty->assign("nameact","Thêm tài khoản");
if(isset($_POST["add-username"]) && isset($_POST["add-password"]) && $_POST["add-username"]!="" && $_POST["add-password"]!="")
{

	$user = addslashes($_POST["add-username"]);
	$pass = addslashes($_POST["add-password"]);
	$query=query("select id from user where username = '$user'");
	if($query)
	{
		$num = numrows($query);
		if($num>0)
			$smarty->assign("msg",$msg["account_exits"]);
		else
		{
			$data=array(
				'id' => "",
				"username" => $user,
				"`password`" => md5($pass),
				"is_active" => 1,
				"`group`" => intval($_POST['group'])
			);
			$ret=insert($data,"user");
			if($ret)
				$smarty->assign("msg",$msg["success"]."<script>setTimeout('location.href=\"".base_admin."?act=user\"',1000);</script>");
			else
				$smarty->assign("msg",$msg["error"]);
		}
			
	}
}
$g=query("select id,name from `group`");
		while($rg=fetch($g))
		{
			$group[]=$rg;
		}
		$smarty->assign("lgroup",$group);
$smarty->display("add-user.htm");

?>